#!/bin/bash
#create users
mkdir -p test
cp ./opensm ./test
cd test

mkdir -p A
mkdir -p ./A/.key
cp ./opensm ./A
cp ../plaintext  ./A/plaintext
./A/opensm -g -k ./A/.key/A.prikey -p ./A/.key/A.pubkey

mkdir -p B
mkdir -p ./B/.key
cp ./opensm ./B
./B/opensm -g -k ./B/.key/B.prikey -p ./B/.key/B.pubkey

rm opensm



#test1
echo ""
echo ""
echo "test1:"
echo "User A encrypts a file"
./A/opensm -e -p ./A/.key/A.pubkey -i ./A/plaintext -o ./A/ciphertext
echo "User A decrypts a file"
./A/opensm -d -k ./A/.key/A.prikey -i ./A/ciphertext -o ./A/dectext
#vimdiff ./A/plaintext ./A/dectext

echo ""
echo ""
echo "test2:"
echo "User A encrypts a file (plaintext) for User B"
./A/opensm -e -p ./B/.key/B.pubkey -i ./A/plaintext -o ./A/ciphertext2
echo "User A sends ciphertext to User B"
mv ./A/ciphertext2 ./B/ciphertext1
echo "User A decrypts the file from User A"
./B/opensm -d -k ./B/.key/B.prikey -i ./B/ciphertext1 -o ./B/dectext1



echo ""
echo ""
echo "test3:"
echo "User A encrypts a file (ciphertext) for User B"
./A/opensm -e -k ./A/.key/A.prikey -p ./B/.key/B.pubkey -i ./A/ciphertext -o ./A/ciphertext3
echo "User A sends ciphertext to User B"
mv ./A/ciphertext3 ./B/ciphertext2
echo "User A decrypts the file from User A"
./B/opensm -d -k ./B/.key/B.prikey -i ./B/ciphertext2 -o ./B/dectext2

echo ""
echo ""

